package conf;

import org.yaml.snakeyaml.Yaml;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.List;

public class YamlDo {

    protected Map<String, Object> data;

    public YamlDo(String yamlString){
        readYamlString(yamlString);
    }

    public YamlDo(String filePath,String fileName) throws FileNotFoundException {
        readYamlFile(filePath+fileName);
    }

    public Map<String, Object> readYamlFile(String fileName) throws FileNotFoundException {
        Yaml yaml = new Yaml();
        FileInputStream inputStream = new FileInputStream(fileName);
        data = yaml.load(inputStream);
        return data;
    }

    public Map<String, Object> readYamlString(String yamlString) {
        Yaml yaml = new Yaml();
        data = yaml.load(yamlString);
        return data;
    }

    public List<Map<String, Object>> getList(String key){
        return (List<Map<String, Object>>) data.get(key);
    }

    public Map<String, Object> getNode(String key){
        return  (Map<String, Object>) data.get(key);
    }

    public String getAttr(String key){
        return  (String) data.get(key);
    }

}
